package com.linln.modules.message.service.impl;

import com.linln.common.data.PageSort;
import com.linln.common.enums.StatusEnum;
import com.linln.modules.message.domain.MessageInfo;
import com.linln.modules.message.domain.MessageTop;
import com.linln.modules.message.repository.MessageInfoRepository;
import com.linln.modules.message.repository.MessageTopRepository;
import com.linln.modules.message.service.MessageTopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author hct
 * @date 2019/09/12
 */
@Service
public class MessageTopServiceImpl implements MessageTopService {

    @Autowired
    private MessageTopRepository messageTopRepository;

    @Autowired
    private MessageInfoRepository messageInfoRepository;


    /**
     * 根据ID查询数据
     * @param id 主键ID
     */
    @Override
    @Transactional
    public MessageTop getById(Long id) {
        return messageTopRepository.findById(id).orElse(null);
    }

    /**
     * 获取分页列表数据
     * @param example 查询实例
     * @return 返回分页数据
     */
    @Override
    public Page<MessageTop> getPageList(Example<MessageTop> example) {
        // 创建分页对象
        PageRequest page = PageSort.pageRequest();
        return messageTopRepository.findAll(example, page);
    }

    
   public  List<MessageTop> getList(Example<MessageTop> example){
	   return messageTopRepository.findAll(example);
   }

    /**
     * 保存数据
     * @param messageTop 实体对象
     */
    @Override
    public MessageTop save(MessageTop messageTop) {
        return messageTopRepository.save(messageTop);
    }

  @Override
  public   boolean delete(Long id) {
    	boolean isOk=false;
    	try {
    	messageTopRepository.deleteById(id);
    	isOk=true;
    	}catch(Exception e) {
    		
    	}
    	return isOk;
    }

    @Override
    public List<MessageInfo> overdueTopList() {
        return messageInfoRepository.overdueTopList();
    }

    @Override
    public Integer leaveTopById(Long id) {
        return messageInfoRepository.leaveTopById(id);
    }
}